import { listDeviceCategoryTree } from '@/apis/asset/common'
import type { TreeNodeData } from '@arco-design/web-vue'
import { ref } from 'vue'

/** 设备分类模块 */
export function deviceCategory(options?: { onSuccess?: () => void }) {
  const loading = ref(false)
  const deviceCategoryList = ref<TreeNodeData[]>([])

  const getDeviceCategoryList = async (name?: string) => {
    try {
      loading.value = true
      const res = await listDeviceCategoryTree({ description: name })
      deviceCategoryList.value = res.data
      options?.onSuccess && options.onSuccess()
    } finally {
      loading.value = false
    }
  }
  return { deviceCategoryList, getDeviceCategoryList, loading }
}
